<script>
export default {
  name: "index",
  data() {
    return {
      videoDetail: {},
      commentList: [
      ],
      show: false,
      comment: ''
    }
  },
  onLoad({ id }) {
    this.$api.getFun(id).then(res => {
      this.videoDetail = res
      this.getCommentList()
    })
  },
  methods: {
    getCommentList() {
      this.$api.getCommentList({
        bus_id: this.videoDetail.id
      }).then(res => {
        this.commentList = res
      })
    },
    navBack() {
      this.$u.route({
        type: 'navigateBack'
      })
    },
    routeTo(path) {
      if (path) {
        this.$u.route({
          type: 'navigateTo',
          url: path
        })
      }
    },

    addComment() {
      this.show = true
    },
    confirm() {
      const user_id = uni.getStorageSync('user_id')
      if (!user_id) {
        // uniapp 确认对话框
        uni.showModal({
          title: '提示',
          content: '请先登录',
          success: function (res) {
            if (res.confirm) {
              uni.navigateTo({
                url: '/pages/user/login'
              })
            }
          }
        })
      }
      if (this.comment) {
        this.$api.addComment({
          bus_id: this.videoDetail.id,
          user_id,
          content: this.comment,
          type: 2
        }).then(res => {
          this.show = false
          this.comment = ''
        })
      }
    }
  }
}
</script>

<template>
  <div class="LawPractice">
    <u-modal v-model="show" @confirm="confirm" ref="uModal" show-confirm-button show-cancel-button>
      <div style="padding: 0 10px">
        <u-input v-model="comment"></u-input>
      </div>
    </u-modal>
    <div class="custom-home-header">
      <div class="title">EasyLaw</div>
      <div class="sub-title">The elbsest ingel ald far ntemsrtlens students</div>
    </div>
    <div class="back-top" @click="navBack">
      <u-icon name="arrow-left" size="28"></u-icon>
      <span class="back-name">LawPractice</span>
    </div>
    <div class="video-detail">
      <div v-if="videoDetail.video_url" v-html="videoDetail.video_url" style="width: 100%;height: 200px"></div>
      <div style="height: 10px"></div>
      <div v-if="videoDetail.image" style="text-align: center">
        <image style="height: 200px" :src="videoDetail.image" alt=""  mode="heightFix" />
      </div>
      <div class="person">
        <u-icon name="account" size="28"></u-icon>
        <span style="margin-left: 10px">{{ commentList.length }}</span>
      </div>
      <div class="title">{{ videoDetail.name }}</div>
      <div class="title">introduction</div>
      <u-line margin="20rpx"></u-line>
      <div class="desc">{{ videoDetail.content }}</div>
      <div class="title">Comment：</div>
      <div class="comment-item" v-for="item in commentList">
        <div class="comment-user">
          <div class="avatar">
            <img :src="item.user.image" alt="">
          </div>
          <div class="userinfo">
            <div>{{ item.user.nickname }}</div>
            <div>{{ item.create_time }}</div>
          </div>
        </div>
        <div class="comment-content">
          {{ item.content }}
        </div>
      </div>

      <button class="confirm-btn" @click="addComment">Add a comment </button>

    </div>
  </div>
</template>

<style  lang="scss">
.LawPractice {
  .confirm-btn{
    width: 630upx;
    height: 56upx;
    line-height: 56upx;
    border-radius: 5px;
    margin-top: 70upx;
    background: rgb(254,149,66);
    color: #fff;
    font-size: $font-lg;
    &:after{
      border-radius: 100px;
    }
  }

  .comment-item{
    display: flex;
    flex-direction: column;
    border-bottom: 1px solid #E4E7ED;
    padding: 20rpx 0;
    .comment-user {
      display: flex;
      .avatar {
        width: 60rpx;
        height: 60rpx;
        img {
          width: 100%;
          height: 100%;
          border-radius: 50%;
        }
      }
      .userinfo {
        margin-left: 20rpx;
        display: flex;
        flex-direction: column;
        justify-content: center;
        div {
          font-size: 24rpx;
          color: #333333;
        }
      }
    }
    .comment-content {
      margin-left: 80rpx;
      font-size: 28rpx;
      color: #666666;
      margin-top: 20rpx;
    }
  }
  .custom-home-header {
    height: 100rpx;
    background-color: #409eff;
    color: #FFFFFF;
    display: flex;
    align-items: center;
    .title {
      font-size: 36rpx;
      line-height: 100rpx;
      padding-left: 50rpx;
    }
    .sub-title {
      font-size: 24rpx;
      color: #a6a2a2;
      margin-left: 20rpx;
      padding-top: 50rpx;
    }
  }

  .back-top {
    display: flex;
    align-items: center;
    padding: 20rpx 0;
  }
  .back-name {
    margin-left: 20rpx;
    font-size: 28rpx;
    color: #333333;
  }
  .video-detail {
    padding: 20rpx 40rpx;
    iframe {
      width: 100%;
      height: 100%;
    }
    .person {
      display: flex;
      justify-content: flex-end;
      align-items: center;
      font-size: 24rpx;
      color: #999999;
      margin-top: 20rpx;
    }
    .title {
      font-size: 28rpx;
      color: #333333;
      margin-top: 20rpx;
      font-weight: bold;
    }
    .desc {
      font-size: 28rpx;
      color: #666666;
      margin-top: 20rpx;
      font-weight: bold;
    }
  }
}
</style>
